package com.sds.batch.util;

import java.util.Date;
import java.util.Set;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;

public class BatchUtil {
	
	private static final Logger logger = LoggerFactory.getLogger(BatchUtil.class);
	
	private BatchUtil() {}
	
	public static JobParameters getUniqueParameters(JobParameters parameters) {
		
		logger.info("###########################################");
		logger.info("----> get Unique JobParameters ...");

		long runId;
		JobParametersBuilder builder = new JobParametersBuilder();

		Set<String> paramSet = parameters.getParameters().keySet();
		for (String key : paramSet) {
			builder.addParameter(key, parameters.getParameters().get(key));
		}

//		if (parameters == null || parameters.isEmpty()) {
//			runId = 1L;
//		} else {
//			runId = parameters.getLong("job.run.id") + 1L;
//		}

//		builder.addLong("job.run.id", runId).toJobParameters();
		 builder.addString("job.batch.id", DateFormatUtils.format(new Date(),
		 "yyyyMMddHHmmssSSS"));

		logger.info("[ JobParameters : " + builder.toJobParameters().toString() + " ]");
		logger.info("###########################################");
		return builder.toJobParameters();
	}
}
